App({
  onLaunch: function() {
    var that = this

    //隐藏系统tabbar
    wx.hideTabBar();
    //获取设备信息
    this.getSystemInfo();

    
  },

  getAccInfo: function(){
    var that = this;
    return new Promise(function(resolve , reject){
      // 登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          if (res.code) {
            wx.request({
              url: that.globalData.url + 'login',
              method: 'POST',
              data: {
                gh_id: 'gh_fa24f2cfb631',
                code: res.code
              },
              success: function(res) {
                // console.log(that.globalData)
                that.globalData.openId = res.data.data.openid
                that.globalData.userId = res.data.data.userid
                that.globalData.level = res.data.data.level
                var result = {
                  status: 200
                }
                resolve(result);
              }
            })
          } else {
            console.log('登录失败' + res.errMsg)
            var res = {
              status: 300
            }
            reject('error');
          }
        }
      })
    })
  },

  getSystemInfo: function() {
    let t = this;
    wx.getSystemInfo({
      success: function(res) {
        t.globalData.systemInfo = res;
      }
    });
  },
  editTabbar: function() {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
  },
  globalData: {
    systemInfo: null, //客户端设备信息
    userInfo: null,
    tabBar: {
      "backgroundColor": "#fa6464",
      "color": "#fff",
      "selectedColor": "#fff",
      "list": [{
          "pagePath": "/pages/index/index",
          "iconPath": "icon/icon_home.png",
          "selectedIconPath": "icon/icon_home_HL.png",
          "text": "首页"
        },
        {
          "pagePath": "/pages/middle/middle",
          "iconPath": "icon/icon_release.png",
          "isSpecial": true,
          "text": ""
        },
        {
          "pagePath": "/pages/mine/mine",
          "iconPath": "icon/icon_mine.png",
          "selectedIconPath": "icon/icon_mine_HL.png",
          "text": "我的"
        }
      ]
    },
    version: '2.0.4',
    userInfo: null,
    referrerInfo: null,
    userId: 0,
    openId: null,
    level:0,
    url: 'https://xcx.nanxuncn.com/api/draw/mopan/',
    imageUrl: 'https://xcx.nanxuncn.com',
    globalFormIds: null,
    nickname: ''
  }
})